<template>
  <div class="aiticlelist">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>文章管理</el-breadcrumb-item>
      <el-breadcrumb-item>文章列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 时间卡片组件 -->
    <el-card class="box-card" style="margin-top: 30px">
      <!-- table表格组件 -->
      <el-table :data="articleList" border style="width: 100%">
        <el-table-column type="index" width="50" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="title" label="标题" width="500" align="center">
        </el-table-column>
        <el-table-column label="类型" width="100" align="center">
          <template slot-scope="scope">
            <!-- scope.row为this.articleList中的每一个元素， -->
            {{ scope.row.type == 1 ? "文章" : "视频" }}
          </template>
        </el-table-column>
        <el-table-column prop="user.nickname" label="作者" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <!-- scope.row为this.articleList中的每一个元素， -->
            <!-- 文字提示 -->
            <el-tooltip
              class="item"
              effect="dark"
              content="编辑"
              placement="top"
            >
              <el-button
                type="primary"
                icon="el-icon-edit"
                @click="handleEdit(scope.row)"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="分享"
              placement="top"
            >
              <el-button type="primary" icon="el-icon-share"></el-button>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="删除"
              placement="top"
            >
              <el-button
                type="primary"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- @size-change  	pageSize (每页多少条)改变时会触发-->
    <!-- @current-change  currentPage （当前页码）改变时会触发 -->
    <!-- page-size  每页显示条目个数 -->
    <!-- total  总条目数 -->
    <!-- current-page  当前页数 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageIndex"
      :page-sizes="[5, 7, 9, 11]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      style="margin-top: 30px"
    >
    </el-pagination>
  </div>
</template>

<script>
import { getArticleList } from "@/api/article";
export default {
  data() {
    return {
      articleList: [],
      pageIndex: 1, //当前页码
      pageSize: 5, //每页多少条
      total: 0, //总数
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    // 页面渲染
    async init() {
      let res = await getArticleList({
        pageIndex: this.pageIndex,
        pageSize: this.pageSize,
      });
      console.log(res);
      this.articleList = res.data.data;
      this.total = res.data.total;
    },
    // 编辑
    handleEdit(row) {
      console.log(row);
    },
    // 删除
    handleDelete(row) {
      console.log(row);
    },
    // <!-- @size-change  	pageSize (每页多少条)改变时会触发-->
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.init();
    },
    // !-- @current-change  currentPage （当前页码）改变时会触发 -->
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageIndex = val;
      this.init();
    },
  },
};
</script>

<style>
</style>